package com.tbit.uqbike.webmanager.controller;

import com.tbit.uqbike.object.business.PageData;
import com.tbit.uqbike.object.pojo.MachineStatusFlag;
import com.tbit.uqbike.object.view.JsonResult;
import com.tbit.uqbike.service.business.NoProfitMachineService;
import com.tbit.uqbike.service.rpcservice.MachineManagerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * @author ：hzw
 * @date ：Created in 2021/9/6 9:28
 * @description：无盈利车辆控制层
 * @modified By：
 * @version: $
 */
@RestController
@RequestMapping(value = "/noProfitMachine")
public class NoProfitMachineController extends BaseController {
    @Autowired
    private NoProfitMachineService noProfitMachineService;
    @Autowired
    private MachineManagerService machineManagerService;

    /**
     * 查询无盈利车辆的详情
     *
     * @return
     */
    @RequestMapping("/viewDetails")
    public JsonResult ViewDetails(Integer accountId, Integer count) {
        List<MachineStatusFlag> list = noProfitMachineService.queryPage(accountId, count);
        return JsonResult.ok(list, list.size());
    }


    /**
     * 导出无盈利车辆
     *
     * @return
     */
    @RequestMapping("/ExcelDetails")
    public void ExcelDetails(Integer accountId, Integer count, HttpServletResponse response) {
        List<MachineStatusFlag> list = noProfitMachineService.queryPage(accountId, count);
        PageData<List<MachineStatusFlag>> pageDatas = new PageData<>();
        pageDatas.setData(list);
        export(pageDatas, machineManagerService, response);
    }
}
